<template>
  <div/>
</template>

<script>
import baseAPI from '@/api/api_base'
export default {
  name: 'TgForm',
  data() {
    return {
      loading: true,
      initParams: {
        isSerach: true
      },
      filters: {
        model: 'company',
        name: ''
      },
      page: {
        totalCount: 0,
        page: 1,
        limit: 10,
        currentPage: 1
      },
      domainList: [],
      domain: {}
    }
  },
  mounted() {
    if (this.initParams.isSerach) {
      this.handleSearch()
    }
  },
  methods: {
    handleSearch() {
      this.page.page = 1
      this.search()
    },
    // 分页查询
    search: function() {
      const _this = this
      const params = {}
      Object.assign(params, this.page, this.filters)
      this.loading = true

      baseAPI.qryByPage(params).then(function(result) {
        _this.loading = false
        if (result) {
          _this.page.totalCount = result.data.totalCount
          _this.domainList = result.data.result
        }
      }, function(err) {
        _this.loading = false
        _this.$message.error({ showClose: true, message: err.toString(), duration: 2000 })
      }).catch(function(err) {
        _this.loading = false
        _this.$message.error({ showClose: true, message: err.toString(), duration: 2000 })
      })
    },
    // 根据ID,删除
    doDel(bizId) {
      const _this = this
      this.$confirm('此操作将删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const params = { 'id': bizId, 'model': _this.filters.model }
        baseAPI.doDel(params).then(result => {
          _this.handleSearch()
        })
      }).catch(() => {
      })
    },
    // 调整到详情页
    doShow(bizId) {
      console.error('调整到详情页')
    },
    // 弹出编辑框
    // 弹出修改框
    // 改变一页数量
    handleSizeChange(pageSize) {
      this.page.pageSize = pageSize
      this.search()
    },
    // 点击第几页
    handleCurrentChange(pageNumber) {
      this.page.pageNumber = pageNumber
      this.search()
    },
    getById(id) {
      const _this = this
      const params = { id: id }
      Object.assign(params, this.filters)
      baseAPI.getById(params).then(function(result) {
        if(result) {
          _this.domain = result.data
        }
      })
    },
    doAddOrUpdate(callBack) {
      const params = {}
      Object.assign(params, this.filters, this.domain)
      const _this = this
      baseAPI.doAddOrUpdate(params).then(result=> {
        callBack()
      })
    }
  },
  // 到改页面到时候，执行查询方法
}
</script>

<style scoped>

</style>
